package com.lifang.imsoa.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class SortUtils {

    public static List<String> listSort(List<String> li) {
        List<String> lt = new ArrayList<String>();
        Map<String, Long> map = new TreeMap<String, Long>();
        for (String str : li) {
            str = str.trim();
            String str2 = "";
            if (str != null && !"".equals(str)) {
                for (int i = 0; i < str.length(); i++) {
                    if (str.charAt(i) >= 48 && str.charAt(i) <= 57) {
                        str2 += str.charAt(i);
                    }
                }
            }
			map.put(str, Long.parseLong(str2 == "" ? "0" : str2));
        }
        List<Map.Entry<String, Long>> mappingList = new ArrayList<Map.Entry<String, Long>>(map.entrySet());
        //通过比较器实现比较排序 
        Collections.sort(mappingList, new Comparator<Map.Entry<String, Long>>() {
            public int compare(Map.Entry<String, Long> mapping1, Map.Entry<String, Long> mapping2) {
                return mapping1.getValue().compareTo(mapping2.getValue());
            }
        });
        for (Map.Entry<String, Long> mapping : mappingList) {
            lt.add(mapping.getKey());
        }
        return lt;

    }

}
